/**
 * src/api/shop.js
 * Mocking client-server processing
 */
/**
 * Mocking client-server processing
 */
export interface IProduct {
  id: number
  title: string
  price: number
  inventory: number
}

const _products: IProduct[] = [
  { id: 1, title: 'iPhone 13 Pro ', price: 500.01, inventory: 2 },
  { id: 2, title: '红米Note 11 Pro', price: 10.99, inventory: 10 },
  { id: 3, title: '华为 P50 Pro', price: 999.99, inventory: 5 }
]

export const getProducts = async () => {
  await wait(100)
  return _products
}

export const buyProducts = async () => {
  await wait(100)
  return Math.random() > 0.5
}

async function wait(delay: number) {
  return new Promise((resolve) => setTimeout(resolve, delay))
}